﻿
using System.Collections.Generic;

namespace LxCFD
{
    public abstract class Value2List
    {
        public abstract class Base<T> : Value2Base<T>
        {
            public List<Value1Base<T>> Value1s = new List<Value1Base<T>>();
            public List<Value2Base<T>> Value2s = new List<Value2Base<T>>();
        }
        public class Double : Base<double>
        {
            public override Value2Base<double> GetCopy(HeadBase zoneOrContact)
            {
                Double copy = new Double();
                foreach (var l in Value1s)
                {
                    copy.Value1s.Add(l.GetCopy(zoneOrContact));
                }
                foreach (var l in Value2s)
                {
                    copy.Value2s.Add(l.GetCopy(zoneOrContact));
                }
                return copy;
            }
            public override void GetCellValue(out double S_Ad, out double S_b, int cellIndex)
            {
                S_Ad = 0;
                S_b = 0;
                foreach (var v in Value1s)
                {
                    S_b += v.GetCellValue(cellIndex);
                }
                foreach (var v in Value2s)
                {
                    v.GetCellValue(out double sa, out double sb, cellIndex);
                    S_Ad += sa;
                    S_b += sb;
                }
            }
            public override void GetFaceValue(out double S_Ad, out double S_b, int faceIndex)
            {
                S_Ad = 0;
                S_b = 0;
                foreach (var v in Value1s)
                {
                    S_b += v.GetFaceValue(faceIndex);
                }
                foreach (var v in Value2s)
                {
                    v.GetFaceValue(out double sa, out double sb, faceIndex);
                    S_Ad += sa;
                    S_b += sb;
                }
            }
        }
        public class Vector : Base<Vector3d>
        {
            public override Value2Base<Vector3d> GetCopy(HeadBase zoneOrContact)
            {
                Vector copy = new Vector();
                foreach (var l in Value1s)
                {
                    copy.Value1s.Add(l.GetCopy(zoneOrContact));
                }
                foreach (var l in Value2s)
                {
                    copy.Value2s.Add(l.GetCopy(zoneOrContact));
                }
                return copy;
            }
            public override void GetCellValue(out Vector3d va, out Vector3d vb, int cellIndex)
            {
                va = new Vector3d();
                vb = new Vector3d();
                foreach (var v in Value1s)
                {
                    vb.AddToSelf(v.GetCellValue(cellIndex));
                }
                foreach (var v in Value2s)
                {
                    v.GetCellValue(out Vector3d a, out Vector3d b, cellIndex);
                    va.AddToSelf(a);
                    vb.AddToSelf(b);
                }
            }
            public override void GetFaceValue(out Vector3d va, out Vector3d vb, int faceIndex)
            {
                va = new Vector3d();
                vb = new Vector3d();
                foreach (var v in Value1s)
                {
                    vb.AddToSelf(v.GetFaceValue(faceIndex));
                }
                foreach (var v in Value2s)
                {
                    v.GetFaceValue(out Vector3d a, out Vector3d b, faceIndex);
                    va.AddToSelf(a);
                    vb.AddToSelf(b);
                }
            }
        }
    }
}
